/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package data;
import business.BuatResep;
import java.sql.*;

/**
 *
 * @author Abdan
 */
public class BuatResepDb extends ConnectionManager {
    public static boolean cekResep(String judul_resep) {
        Statement st = null;
        ResultSet rs = null;
        boolean x =true;

        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection(url + dbname, user, password);
            st = conn.createStatement();
            rs = st.executeQuery("Select * from resep where judul_resep = '"+ judul_resep +"')");

            if(rs.next()){
                x = false;
            }else{
                x=true;
            }
        }
        catch(Exception e){

        }
        return x;
    }
    public static BuatResep InsertResep(String nama_resep, int waktu, int porsi, String tanggal) {
        BuatResep buat = new BuatResep();
        Statement st = null;
        ResultSet rs = null;

        System.out.println("INSERT INTO resep(judul_resep,waktu_masak,porsi,tanggal) VALUES ('" + nama_resep + "','" + waktu + "','" + porsi + "','" + tanggal +"')");
        try{
            st = conn.createStatement();

            st.executeUpdate("INSERT INTO resep(judul_resep,waktu_masak,porsi,tanggal) VALUES ('" + nama_resep + "','" + waktu + "','" + porsi + "','" + tanggal +"')");

        if(rs.next()){
            buat.setNama_resep(rs.getString("judul_resep"));
            buat.setWaktu(Integer.parseInt(rs.getString("waktu_masak")));
            buat.setPorsi(Integer.parseInt(rs.getString("porsi")));
            buat.setTanggal(rs.getString("tanggal"));
        }
        return buat;
        }
        catch(Exception e){
            e.printStackTrace();
            return null;
        }
    }

}
